/*
 * @Author: your name
 * @Date: 2021-11-12 21:39:15
 * @LastEditTime: 2021-12-03 09:35:40
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\serve\app\controller\article.js
 */

const Mock = require("mockjs");
const { list } = Mock.mock({
    "list|20": [{
        content: "",
        title: "@ctitle(10,20)",
        author: "@ctitle",
        "looks|0-99": 1,
        "state|1": [false, true],
        public_time: "@datetime",
        order: 0,
        pathUrl: /^((ht|f)tps?:\/\/)?[\w-]+(\.[\w-]+)+:\d{1,5}\/?$/,
    }, ],
});
const Controller = require("../core/base_controller");
class ArticleController extends Controller {
    async insertList() {
            const { ctx, app } = this;
            list.forEach((item) => {
                app.mysql.insert("page", {...item });
            });
            ctx.body = "添加成功";
        }
        //获取
    async getPage() {
        const { ctx } = this;
        try {
            const res = await ctx.service.page.getPage();
            this.success(res);
        } catch (err) {
            this.error(err.message);
        }
    }
    async changePageState() {
            const { ctx } = this;
            try {
                const res = await ctx.service.page.changePageState();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //删除
    async delPage() {
            const { ctx } = this;
            try {
                const res = await ctx.service.page.delPage();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //添加页面
    async addPage() {
            const { ctx } = this;
            try {
                const res = await ctx.service.page.addPage();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //修改页面
    async editPage() {
            const { ctx } = this;
            try {
                const res = await ctx.service.page.editPage();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //获取页面详情
    async getPageDetail() {
            const { ctx } = this;
            try {
                const res = await ctx.service.page.getPageDetail();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //批量删除
    async batchDelPage() {
            const { ctx } = this;
            try {
                const res = await ctx.service.page.batchDelPage();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //批量发布
    async batchPubPage() {
            const { ctx } = this;
            try {
                const res = await ctx.service.page.batchPubPage();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //批量下线
    async batchDftPage() {
        const { ctx } = this;
        try {
            const res = await ctx.service.page.batchDftPage();
            this.success(res);
        } catch (err) {
            this.error(err.message);
        }
    }

    // ?***********用户端*****************?/
    async getPassPage() {
        const { ctx } = this;
        try {
            const res = await ctx.service.page.getPassPage();
            this.success(res);
        } catch (err) {
            this.error(err.message);
        }
    }
    async getDetailPage() {
        const { ctx } = this;
        try {
            const res = await ctx.service.page.getDetailPage();
            this.success(res);
        } catch (err) {
            this.error(err.message);
        }
    }
}

module.exports = ArticleController;